import { createRouter, createWebHistory } from 'vue-router'
import Index from '../views/IndexView.vue'

// 采用的history写法，如果没有后端在服务器端配合，请使用hash路由，即createWebHashHistory

/**
 * @meta 元信息字段定义
 * title 提供给标题使用
 * topNavMode 区分当前页面顶部导航 默认为全局导航，none为取消全局顶部导航, mainPage不展示左侧返回按钮
 */
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home',
      component: Index,
      meta: { title: '首页' },
      children: [
        {
          path: '/home',
          component: () => import('../views/homeRouterPage/Home.vue'),
          name: 'Index',
          meta: { title: '首页', topNavMode: 'none' }
        },
        {
          path: '/cart',
          component: () => import('../views/homeRouterPage/Cart.vue'),
          name: 'cart',
          meta: { title: 'tab1', topNavMode: 'mainPage' }
        },
        {
          path: '/user',
          component: () => import('../views/homeRouterPage/User.vue'),
          name: 'user',
          meta: { title: 'tab2', topNavMode: 'none' },
        },
      ]
    },
    // 不存在的路径全部转到404页面
    {
      path: '/:catchAll(.*)',
      component: () => import('../views/notFound.vue')
    },
    {
      path: '/404',
      name: 'notFound',
      component: () => import('../views/notFound.vue'),
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue')
    }
  ]
})

export default router
